const express = require('express')
const fs = require('fs')
const config = require(process.cwd() + '/src/config/config')
const tiles = require(process.cwd() + '/src/utils/tiles')

let router = express.Router()

/* GET users listing. */
router.get('/', function(req, res) {
  // images文件夹里的子文件夹就是所有分类
  const tileset = req.query.tileset
  fs.promises.readFile(config.tilesetsPath + tileset + '.json').then((data) => {
    data = JSON.parse(data)
    data.list = tiles.tileImageSrc(data.list, tileset)
    res.json(data)
  })
  .catch((err) => {
    console.log(err)
    res.sendStatus(500)
  })
})

module.exports = router
